package com.jcl.recruit.elasticsearch.mapper;

import com.jcl.recruit.elasticsearch.resume.model.SearchResumeWork;
import com.jcl.recruit.mapper.SqlMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liuyy
 * @date 2018/11/17
 */
public interface SearchResumeWorkMapper extends SqlMapper {

    String TABLE_NAME = "search_resume_work";

    String SQL_INSERT_SUFFIX_ENTITY = " (resume_id,company,duty,position,start_date,end_date) ";

    String SQL_INSERT_SUFFIX_ENTITY_VALUES = " (#{entity.resumeId},#{entity.company},#{entity.duty}," +
            "#{entity.position},#{entity.startDate},#{entity.endDate}) ";

    String SQL_ORDER_START_DATE_DESC = " order by start_date desc ";

    @Select({

            QUERY_SCRIPT_START,
            SQL_QUERY_RESUME_ID,
            SQL_IN,
            FOREACH_START_LIST_RESUME_IDS,
            SQL_PROPERTY_RESUME_ID_VALUE,
            FOREACH_END,
            SQL_ORDER_START_DATE_DESC,
            QUERY_SCRIPT_END
    })
    List<SearchResumeWork> findListByResumeIds(@Param("resumeIds") List<Integer> resumeIds);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_RESUME_ID,
            SQL_EQUAL,
            SQL_PROPERTY_RESUME_ID_VALUE,
            SQL_ORDER_START_DATE_DESC,
            QUERY_SCRIPT_END
    })
    List<SearchResumeWork> findListByResumeId(@Param("resumeId") Integer resumeId);


    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_RESUME_ID,
            SQL_EQUAL,
            SQL_PROPERTY_RESUME_ID_VALUE,
            SQL_ORDER_START_DATE_DESC,
            QUERY_SCRIPT_END
    })
    List<Map<String, Object>> findObjListByResumeId(@Param("resumeId") Integer resumeId);

    @Insert({
            QUERY_SCRIPT_START,
            SQL_INSERT,
            SQL_INSERT_VALUES,
            FOREACH_START_LIST_ENTITY_NO_OPEN,
            SQL_INSERT_SUFFIX_ENTITY_VALUES,
            FOREACH_END,
            QUERY_SCRIPT_END
    })
    int batchInsert(@Param("list") List<SearchResumeWork> list);

    @Delete({
            QUERY_SCRIPT_START,
            SQL_DELETE_RESUME_ID,
            SQL_IN,
            FOREACH_START_LIST_RESUME_IDS,
            SQL_PROPERTY_RESUME_ID_VALUE,
            FOREACH_END,
            QUERY_SCRIPT_END
    })
    int batchDeleteByResumeIds(@Param("resumeIds") List<Integer> resumeIds);

    String SQL_INSERT = "insert into " + TABLE_NAME + SQL_INSERT_SUFFIX_ENTITY;
    String SQL_QUERY_RESUME_ID = "select * from " + TABLE_NAME + " where resume_id ";
    String SQL_DELETE_RESUME_ID = "delete from " + TABLE_NAME + " where resume_id ";

}
